from interface.member import MemberInterface
from utils.send_method import SendMethod


class CartInterface:
    def __init__(self, headers):
        self.url = 'http://47.108.206.100:8085'
        self.headers = headers

    def cart_add(self, body):
        # 添加购物车接口
        method = 'post'  # 请求参数类型json
        url = self.url + '/cart/add'
        return SendMethod.send_method(method=method, url=url, json=body, headers=self.headers)


if __name__ == '__main__':
    body = {
        "username": "liyimei",
        "password": "123456"
    }
    headers = MemberInterface().get_token(body)
    print(headers)
    cart = CartInterface(headers)
    payload = {
        "createDate": "2023-06-16T02:34:25.705Z",
        "deleteStatus": 0,
        "id": 0,
        "memberId": 5607,
        "memberNickname": "tom",
        "modifyDate": "2023-06-16T02:34:25.705Z",
        "price": 2699,
        "productAttr": "[{'key':'颜色', 'value': '红色'},{'key':'容量','value':'64G'}]",
        "productBrand": "iPhone",
        "productCategoryId": 11,
        "productId": 27,
        "productName": "oppo7 全面屏游戏智能手机 6G+64GB 黑色 全网通4G 双卡双待",
        "productPic": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/201805/xiaomi.jpg",
        "productSkuCode": "201808270027001",
        "productSkuId": 98,
        "productSn": "7437788",
        "productSubTitle": "骁龙845处理器，红外人脸解锁，AI变焦双摄",
        "quantity": 1
    }
    print(cart.cart_add(payload))  # 调用添加购物车
